package net.cardgame.orcalecard.pref;

import java.util.Iterator;
import java.util.Map;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class GalleryPreferences {
	public static final int MODE = Context.MODE_PRIVATE;
	public static final String PREF_GALLERY = "GALLERY_PREFERENCES";
	
	public static void writeString(Context context, String key, String value) {
		getEditor(context).putString(key, value).commit();
	}
	
	public static String readString(Context context, String key, String defValue) {
		return getPreferences(context).getString(key, defValue);
	}
	
	public static SharedPreferences getPreferences(Context context) {
		return context.getSharedPreferences(PREF_GALLERY, MODE);
	}

	public static Editor getEditor(Context context) {
		return getPreferences(context).edit();
	}
	
	@SuppressWarnings("rawtypes")
	public static boolean checkKey(Context context, String key) {
		SharedPreferences sharedPreferences = getPreferences(context);
		Iterator iter = sharedPreferences.getAll().entrySet().iterator();
	    while (iter.hasNext()) {
	        Map.Entry pair = (Map.Entry)iter.next();
	        if (pair.getKey().toString().equals(key))
	        	return true;
	    }
	    return false;
	}
}
